home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-01-13 | 10.5 KB | 347 lines | [TEXT/CWIE] |
- // ----------------------------------------------------------------------
- //
- // Module:
- // CustomEnabler.c
- //
- // Purpose:
- // SystemSoft custom enabler to support multiple cards
- //
- // Authors:
- // Andrew Dallas
- // Dave Tarabar
- //
- // Copyright: © 1996 SystemSoft Corporation, all rights reserved.
- // ----------------------------------------------------------------------
-
- #include <DriverSupport.h>
- #include <Errors.h>
- #include <PCCardEnablerPlugin.h>
- #include <PCCardTuples.h>
-
- //#define DEBUG_ON 1
- #ifdef DEBUG_ON
- #define DebugMessage(x) SysBreakStr(x)
- #else
- #define DebugMessage(x)
- #endif
-
- //----------------------------------------------------------------------
- // list of supported card's MANFID tuple (in Intel Byte order)
-
- // Dayna "CommuniCard E" EtherNet Adapter P/N 98056-01
- #define kDaynaManfID 0x0194002D
- // Megahertz Gold Series 14.4 Fax Modem
- #define kMegahertzManfID 0x02010500
-
- typedef enum {
- kUnsupportedCardID = 0,
- kDaynaCommunicardEthernetAdapter,
- kMegahertzGoldSeries14_4FaxModem
-
- } SupportedCardID, *SupportedCardIDPtr;
-
- SupportedCardID gThisCardID = kUnsupportedCardID;
-
- //----------------------------------------------------------------------
- // Local Prototypes
- OSStatus MyValidateHardware(const RegEntryRef * lpCardEntry);
- OSStatus MyGetDeviceCount(const RegEntryRef * lpParentID,UInt32 *lpCount);
- OSStatus MyGetDeviceType(const RegEntryRef * lpDevice,UInt32 socket,UInt32 device,PCDeviceType *lpDeviceType);
- OSStatus MyGetFirstTuple(UInt32 socket, UInt32 device, PCCardTupleIterator lpTupleIterator,
- Byte desiredTuple, void *lptupleData, UInt32 *lpTupleBufferSize, Byte *lpFoundTuple);
-
- OSStatus _IdentifyCard(const RegEntryRef * lpCardEntry, SupportedCardIDPtr lpCardType);
- Boolean CheckVers1Tuple(unsigned char * data, char * manufacturerName, char * cardName);
-
- //----------------------------------------------------------------------
- // Globals
-
- #define kVersionMajor 1
- #define kVersionMinor 0
- #define kVersionStage developStage
- #define kVersionNonRel 1
- #define kPluginNamePString "\pSuperPCCardEnabler"
-
- #pragma export on
-
- // --------------------
- // Here's the exported Driver Descriptor
- DriverDescription TheDriverDescription = {
- /*
- * Signature info
- */
- kTheDescriptionSignature, /* OSType driverDescSignature */
- kInitialDriverDescriptor, /* DriverDescVersion driverDescVersion */
- /*
- * DriverType driverType - these are defined in
- */
- kPluginNamePString, /* Name of hardware */
- kVersionMajor, kVersionMinor, /* NumVersion version */
- kVersionStage, kVersionNonRel,
-
- /*
- * DriverOSRuntime driverOSRuntimeInfo
- */
- 0 /* RuntimeOptions driverRuntime */
- | (1 * kDriverIsLoadedUponDiscovery) /* Loader runtime options */
- | (0 * kDriverIsOpenedUponLoad) /* Opened when loaded */
- | (1 * kDriverIsUnderExpertControl) /* I/O expert handles loads/opens */
- | (0 * kDriverIsConcurrent) /* Not concurrent yet */
- | (0 * kDriverQueuesIOPB), /* Not internally queued yet */
- kPluginNamePString, /* Str31 driverName (OpenDriver param) */
- 0, 0, 0, 0, 0, 0, 0, 0, /* UInt32 driverDescReserved[8] */
-
- /*
- * DriverOSService Information. This section contains a vector count followed by
- * a vector of structures, each defining a driver service.
- */
- 1, /* ServiceCount nServices */
-
- /*
- * DriverServiceInfo service[0]
- */
- kServiceCategoryPCCard, /* OSType serviceCategory */
- kServiceTypePCCardEnabler, /* OSType serviceType */
-
- 1, 0,developStage, 1 /* version of the Open Transport */
- /* programming interface that this */
- /* driver supports */
- /* should be kOTDriverAPIVersion */
- };
-
-
- // --------------------
- // Here's the exported Plugin Function Table…
- PCCardEnablerPluginDispatchTable ThePluginDispatchTable =
- {
- /* PCCardEnablerPluginHeader */
- { kPCCardEnablerPluginCurrentVersion, 0, 0, 0 },
-
- /* CEValidateHardwareProc */ MyValidateHardware,
- /* CEInitializeProc */ CEInitializeCard,
- /* CECleanupProc */ CEFinalizeCard,
- /* CEPowerManagementProc */ CEPowerManagement,
-
- /* CEHandleEventProc */ CEHandleCardEvent,
- /* CEGetCardInfoProc */ CEGetCardInfo,
- /* CEAddCardPropertiesProc */ CEAddCardProperties,
- /* CEGetDeviceCountProc */ MyGetDeviceCount,
-
- /* CEGetDeviceNameProc */ CEGetDeviceName,
- /* CEGetDeviceCompatibleNameProc */ CEGetDeviceCompatibleNames,
- /* CEGetDeviceTypeProc */ MyGetDeviceType,
- /* CEGetDeviceTypeNameProc */ CEGetDeviceTypeName,
- /* CEAddDevicePropertiesProc */ CEAddDeviceProperties,
- /* CEConfigureDeviceProc */ CEConfigureDevice,
- /* CEFinalizeDeviceProc */ CEFinalizeDevice,
-
- /* CEValidateCISProc */ CEValidateCIS,
- /* CEGetFirstTupleProc */ MyGetFirstTuple,
- /* CEGetNextTupleProc */ CSGetNextTuple,
-
- /* InterruptHandler */ CEDefaultInterruptHandler,
- /* InterruptEnabler */ NULL,
- /* InterruptDisabler */ NULL
- };
-
- #pragma export off
-
- //----------------------------------------------------------------------
- // Determine whether the plugin can support this card.
- // Returning noErr means that the card is supported
- OSStatus MyValidateHardware(const RegEntryRef *lpCardEntry)
- {
- OSStatus err;
-
- if (!(lpCardEntry)) return(paramErr);
-
- // see if we are supposed to handle this card, set global card id
- err = _IdentifyCard(lpCardEntry, &gThisCardID);
-
- #ifdef DEBUG_ON
- if (err == noErr) DebugStr("\pCardWizard will handle this card!;g");
- #endif
- return(err);
- }
-
-
- //----------------------------------------------------------------------
- // Look to see if this is a card we are supposed to handle
- // If it is return noErr, other wise return kUnsupportedCardErr
- OSStatus _IdentifyCard(const RegEntryRef *lpCardEntry, SupportedCardIDPtr lpCardType)
- {
- PCCardTupleIterator iter;
- OSStatus err = noErr;
- unsigned char tuple[MAX_TUPLE_SIZE];
- UInt32 size, manfID, socket, device;
- Byte foundTuple;
-
- if(!(lpCardEntry && lpCardType)) return(paramErr);
-
- // assume the card is unsupported
- *lpCardType = kUnsupportedCardID;
-
- err = CEGetSocketAndDeviceFromRegEntry(lpCardEntry, &socket, &device);
- if (err != noErr)
- return(err);
-
- iter = PCCardNewTupleIterator();
- if (iter == NULL)
- return memFullErr;
-
- // get the MANFID form the tuples
- size = sizeof(UInt32);
- err = CSGetFirstTuple(socket, device, iter, CISTPL_MANFID, &manfID, &size, &foundTuple);
-
- // if the MANFID matches, then verify it is the card we want
- switch(manfID)
- {
- case kDaynaManfID:
- // this is a Dayna card. See which one...
- size = MAX_TUPLE_SIZE;
- err = CSGetFirstTuple(socket, device, iter, CISTPL_VERS_1, tuple, &size, &foundTuple);
-
- if(err == noErr)
- if (CheckVers1Tuple(tuple, "Dayna Communications, Inc.", "CommuniCard E"))
- *lpCardType = kDaynaCommunicardEthernetAdapter;
- break;
-
- case kMegahertzManfID:
- // this is a Megahertz card. See which one...
- size = MAX_TUPLE_SIZE;
- err = CSGetFirstTuple(socket, device, iter, CISTPL_VERS_1, tuple, &size, &foundTuple);
-
- if(err == noErr)
- if (CheckVers1Tuple(tuple, "MEGAHERTZ", "CC3144"))
- *lpCardType = kMegahertzGoldSeries14_4FaxModem;
- break;
-
- }
-
- (void) PCCardDisposeTupleIterator(iter);
- // return whether or not we support the card
- if (*lpCardType == kUnsupportedCardID)
- return(kUnsupportedCardErr);
- else
- return(noErr);
- }
-
-
- //----------------------------------------------------------------------
- // no need for this yet, so just call the default
- OSStatus MyGetDeviceCount(const RegEntryRef * lpParentID, UInt32 *lpCount)
- {
- OSStatus retval;
-
- if (!(lpCount && lpParentID)) return(paramErr);
-
- retval = CEGetDeviceCount(lpParentID, lpCount);
-
- return(retval);
- }
-
-
- //----------------------------------------------------------------------
- // The Megahertz card needs to override the GetDeviceType
- OSStatus MyGetDeviceType(const RegEntryRef * lpDevice,UInt32 socket,UInt32 device,PCDeviceType *lpDeviceType)
- {
- OSStatus err;
-
- if (!(lpDevice && lpDeviceType)) return(paramErr);
-
- // see if we need to override the get device type
- switch (gThisCardID)
- {
- case kMegahertzGoldSeries14_4FaxModem:
- *lpDeviceType = kSerialDeviceType;
- DebugMessage("\pMegahertz Gold override GetDeviceType;g");
- return (noErr);
- break;
- }
-
- // this call was not overridden, so call the default behavior
- err = CEGetDeviceType(lpDevice, socket, device, lpDeviceType);
-
- return(err);
- }
-
-
- //----------------------------------------------------------------------
- // The Megahertz card needs to override the CISTPL_FUNCID tuple
- // The Dayna card needs to override the CISTPL_FUNCE tuple
- // REVIEW: we should set foundTuple and make sure the buffersize is big enough
- OSStatus MyGetFirstTuple(UInt32 socket, UInt32 device,
- PCCardTupleIterator lpTupleIterator,
- Byte desiredTuple,
- void *lptupleData,
- UInt32 *lpTupleBufferSize,
- Byte *lpFoundTuple)
- {
- OSStatus err = noErr;
- unsigned char *dataPtr = (unsigned char *)lptupleData;
-
- if(!(lpTupleIterator && lpFoundTuple && dataPtr && *lpTupleBufferSize))
- return(paramErr);
-
- // see if we need to override for a specific card and tuple type
- switch(gThisCardID)
- {
- case kDaynaCommunicardEthernetAdapter:
- if(desiredTuple == CISTPL_FUNCE)
- {
- // fake an ethernet FUNCE (page 52 of metaformat spec)
- dataPtr[0] = 0x01; // LAN_TECH
- dataPtr[1] = 0x02; // ethernet
- dataPtr[2] = 0xFF;
- DebugMessage("\pDayna Communicard E override GetFirstTuple;g");
- *lpTupleBufferSize = 3;
- return (noErr);
- }
- break;
-
- case kMegahertzGoldSeries14_4FaxModem:
- if(desiredTuple == CISTPL_FUNCID)
- {
- // fake a serial FUNCID
- dataPtr[0] = 0x02;
- dataPtr[1] = 0x00;
- *lpTupleBufferSize = 2;
- DebugMessage("\pMegahertz Gold override GetFirstTuple;g");
- return (noErr);
- }
- break;
- }
-
- // this call was not overridden, so call the default behavior
- err = CSGetFirstTuple(socket, device,lpTupleIterator,desiredTuple,
- lptupleData,lpTupleBufferSize,lpFoundTuple);
-
- return(err);
- }
-
-
- //----------------------------------------------------------------------
- // Pass in a VERS1 tuple and check that the manufacturer name and card name are
- // the the same as the ones passed in
- Boolean CheckVers1Tuple(unsigned char * data, char * manufacturerName, char * cardName)
- {
- unsigned char *ptr;
-
- // the manufacturer name is a null terminated string starting in byte three
- ptr = &(data[2]);
- if(CStrCmp((const char *) ptr, manufacturerName) == 0)
- {
- // the card name is a null terminated string that starts after the manufacturer name
- while(*ptr++)
- ;
- if(CStrCmp((const char *) ptr, cardName) != 0)
- return(false);
- }
- else
- return(false);
-
- // if we make it to here, both names match
- return(true);
- }
-
-